#define _gam_stock_included 1

#if !defined _gam_globals_included
	#include <gam/globals>
#endif

getLevelName(id, level, name[] ,len){
	switch(level) {
		case LEVEL_BEGINNER: formatex(name, len, "%L", id, "LEVEL_BEGINNER");
		case LEVEL_BASIC: formatex(name, len, "%L", id, "LEVEL_BASIC");
		case LEVEL_ADVANCED: formatex(name, len, "%L", id, "LEVEL_ADVANCED");
		case LEVEL_EXPERT: formatex(name, len, "%L", id, "LEVEL_EXPERT");
		case LEVEL_VETERAN: formatex(name, len, "%L", id, "LEVEL_VETERAN");
		case LEVEL_HITMAN: formatex(name, len, "%L", id, "LEVEL_HITMAN");
		case LEVEL_OWNER: formatex(name, len, "%L", id, "LEVEL_OWNER");
	}
}

getWeaponName4Level(id, wpn, name[], len) {
	switch(wpn){
		case WEAPONS_P228: formatex(name, len, "%L", id, "WEAPONS_P228_4_LEVEL");
		case WEAPONS_SCOUT: formatex(name, len, "%L", id, "WEAPONS_SCOUT_4_LEVEL");
		case WEAPONS_HEGRENADE: formatex(name, len, "%L", id, "WEAPONS_HEGRENADE_4_LEVEL");
		case WEAPONS_XM1014: formatex(name, len, "%L", id, "WEAPONS_XM1014_4_LEVEL");
		case WEAPONS_MAC10: formatex(name, len, "%L", id, "WEAPONS_MAC10_4_LEVEL");
		case WEAPONS_AUG: formatex(name, len, "%L", id, "WEAPONS_AUG_4_LEVEL");
		case WEAPONS_ELITE: formatex(name, len, "%L", id, "WEAPONS_ELITE_4_LEVEL");
		case WEAPONS_FIVESEVEN: formatex(name, len, "%L", id, "WEAPONS_FIVESEVEN_4_LEVEL");
		case WEAPONS_UMP45: formatex(name, len, "%L", id, "WEAPONS_UMP45_4_LEVEL");
		case WEAPONS_SG550: formatex(name, len, "%L", id, "WEAPONS_SG550_4_LEVEL");
		case WEAPONS_GALIL: formatex(name, len, "%L", id, "WEAPONS_GALIL_4_LEVEL");
		case WEAPONS_FAMAS: formatex(name, len, "%L", id, "WEAPONS_FAMAS_4_LEVEL");
		case WEAPONS_USP: formatex(name, len, "%L", id, "WEAPONS_USP_4_LEVEL");
		case WEAPONS_GLOCK18: formatex(name, len, "%L", id, "WEAPONS_GLOCK18_4_LEVEL");
		case WEAPONS_AWP: formatex(name, len, "%L", id, "WEAPONS_AWP_4_LEVEL");
		case WEAPONS_MP5NAVY: formatex(name, len, "%L", id, "WEAPONS_MP5NAVY_4_LEVEL");
		case WEAPONS_M249: formatex(name, len, "%L", id, "WEAPONS_M249_4_LEVEL");
		case WEAPONS_M3: formatex(name, len, "%L", id, "WEAPONS_M3_4_LEVEL");
		case WEAPONS_M4A1: formatex(name, len, "%L", id, "WEAPONS_M4A1_4_LEVEL");
		case WEAPONS_TMP: formatex(name, len, "%L", id, "WEAPONS_TMP_4_LEVEL");
		case WEAPONS_G3SG1: formatex(name, len, "%L", id, "WEAPONS_G3SG1_4_LEVEL");
		case WEAPONS_DEAGLE: formatex(name, len, "%L", id, "WEAPONS_DEAGLE_4_LEVEL");
		case WEAPONS_SG552: formatex(name, len, "%L", id, "WEAPONS_SG552_4_LEVEL");
		case WEAPONS_AK47: formatex(name, len, "%L", id, "WEAPONS_AK47_4_LEVEL");
		case WEAPONS_KNIFE: formatex(name, len, "%L", id, "WEAPONS_KNIFE_4_LEVEL");
		case WEAPONS_P90: formatex(name, len, "%L", id, "WEAPONS_P90_4_LEVEL");
	}
}
getRankName(id, rank, name[], len){
	switch(rank){
		case RANK_PRIVATE: formatex(name, len, "%L", id, "RANK_PRIVATE");
		case RANK_OLDER_PRIVATE: formatex(name, len, "%L", id, "RANK_OLDER_PRIVATE");
		case RANK_FIRST_CLASS_PRIVATE: formatex(name, len, "%L", id, "RANK_FIRST_CLASS_PRIVATE");
		case RANK_SPECJALIST: formatex(name, len, "%L", id, "RANK_SPECJALIST");
		case RANK_CORPORAL: formatex(name, len, "%L", id, "RANK_CORPORAL");
		case RANK_SERGEANT: formatex(name, len, "%L", id, "RANK_SERGEANT");
		case RANK_STAFF_SERGEANT: formatex(name, len, "%L", id, "RANK_STAFF_SERGEANT");
		case RANK_SERGEANT_FIRST_CLASS: formatex(name, len, "%L", id, "RANK_SERGEANT_FIRST_CLASS");
		case RANK_MASTER_SERGEANT: formatex(name, len, "%L", id, "RANK_MASTER_SERGEANT");
		case RANK_FIRST_SERGEANT: formatex(name, len, "%L", id, "RANK_FIRST_SERGEANT");
		case RANK_SERGEANT_MAJOR: formatex(name, len, "%L", id, "RANK_SERGEANT_MAJOR");
		case RANK_COMMAND_SERGEANT_MAJOR: formatex(name, len, "%L", id, "RANK_COMMAND_SERGEANT_MAJOR");
		case RANK_SERGEANT_MAJOR_OF_THE_ARMY: formatex(name, len, "%L", id, "RANK_SERGEANT_MAJOR_OF_THE_ARMY");
		case RANK_SECOND_LIEUTENANT: formatex(name, len, "%L", id, "RANK_SECOND_LIEUTENANT");
		case RANK_FIRST_LIEUTENANT: formatex(name, len, "%L", id, "RANK_FIRST_LIEUTENANT");
		case RANK_CAPTAIN: formatex(name, len, "%L", id, "RANK_CAPTAIN");
		case RANK_MAJOR: formatex(name, len, "%L", id, "RANK_MAJOR");
		case RANK_LIEUTENANT_COLONEL: formatex(name, len, "%L", id, "RANK_LIEUTENANT_COLONEL");
		case RANK_COLONEL: formatex(name, len, "%L", id, "RANK_COLONEL");
		case RANK_BRIDAGIER_GENERAL: formatex(name, len, "%L", id, "RANK_BRIDAGIER_GENERAL");
		case RANK_MAJOR_GENERAL: formatex(name, len, "%L", id, "RANK_MAJOR_GENERAL");
		case RANK_LIEUTENANT_GENERAL: formatex(name, len, "%L", id, "RANK_LIEUTENANT_GENERAL");
		case RANK_GENERAL: formatex(name, len, "%L", id, "RANK_GENERAL");
		case RANK_GENERAL_OF_THE_ARMY: formatex(name, len, "%L", id, "RANK_GENERAL_OF_THE_ARMY");
	}
}
getWeaponByShortName(const weaponName[]) {
	if(equali(weaponName, "p228")) return WEAPONS_P228;
	if(equali(weaponName, "scout")) return WEAPONS_SCOUT;
	if(equali(weaponName, "grenade")) return WEAPONS_HEGRENADE;
	if(equali(weaponName, "xm1014")) return WEAPONS_XM1014;
	if(equali(weaponName, "mac10")) return WEAPONS_MAC10;
	if(equali(weaponName, "aug")) return WEAPONS_AUG;
	if(equali(weaponName, "elite")) return WEAPONS_ELITE;
	if(equali(weaponName, "fiveseven")) return WEAPONS_FIVESEVEN;
	if(equali(weaponName, "ump45")) return WEAPONS_UMP45;
	if(equali(weaponName, "sg550")) return WEAPONS_SG550;
	if(equali(weaponName, "galil")) return WEAPONS_GALIL;
	if(equali(weaponName, "famas")) return WEAPONS_FAMAS;
	if(equali(weaponName, "usp")) return WEAPONS_USP;
	if(equali(weaponName, "glock18")) return WEAPONS_GLOCK18;
	if(equali(weaponName, "awp")) return WEAPONS_AWP;
	if(equali(weaponName, "mp5navy")) return WEAPONS_MP5NAVY;
	if(equali(weaponName, "m249")) return WEAPONS_M249;
	if(equali(weaponName, "m3")) return WEAPONS_M3;
	if(equali(weaponName, "m4a1")) return WEAPONS_M4A1;
	if(equali(weaponName, "tmp")) return WEAPONS_TMP;
	if(equali(weaponName, "g3sg1")) return WEAPONS_G3SG1;
	if(equali(weaponName, "deagle")) return WEAPONS_DEAGLE;
	if(equali(weaponName, "sg552")) return WEAPONS_SG552;
	if(equali(weaponName, "ak47")) return WEAPONS_AK47;
	if(equali(weaponName, "knife")) return WEAPONS_KNIFE;
	if(equali(weaponName, "p90")) return WEAPONS_P90;
	return -1;	
}

bool:isLevelWeapon(weapon){
	switch(weapon){
		case WEAPONS_BLANK, WEAPONS_NOTHING, WEAPONS_FLASHBANG, WEAPONS_SMOKEGRENADE, WEAPONS_C4: return false;
	}
	return true;
}

stock bool:isEnoughPlayers(){
	if(get_playersnum()< get_pcvar_num(gCvarMinPlayers) )
		return false;
	return true;
}

stock isActive(){
	return get_pcvar_num(gCvarActive);
}


stock bool:isPlayer(id){
	if (0<id<gMaxPlayers)
		return true;
	return false;
}
stock bool:isPlayerAuthorized(id){
	if(gPlayerKey[id][0])
		return true;
	return false;
}

stock bool:isLevelPowers(){
	if(get_pcvar_num(gCvarLevelPowers))
		return true;
	return false;
}

stock bool:isBuyTime(){
	new Float:timepassed = get_gametime() - gRoundTime;
	new Float:buytime = gBuyTime * 60.0 + gFreezTime;
	if(floatcmp(timepassed , buytime) == 1)
		return false;	
	return true;
}

stock clearUserRoundXp(id){
	gPlayerXp[id][T_ROUND] = 0;
	for(new wpn=WEAPONS_P228;wpn<WEAPONS;wpn++) {
		gPlayerInfo[id][wpn][REQ_HS_ROUND] = 0;
		gPlayerInfo[id][wpn][REQ_KILLS_ROUND] = 0;
	}
}
stock clearPlayerInfo(id){
	server_print("clearPlayerInfo(%d)", id);
	gPlayerKey[id][0] = 0;
	gPlayerXp[id] = {0,0,0};
	gPlayerRank[id] = RANK_PRIVATE;
	
	for(new wpn=WEAPONS_P228;wpn<=WEAPONS_P90;wpn++){
		gPlayerInfo[id][wpn] = {0,0,0,0,0,0};
		gPlayerLevelReq[id][wpn] = {0,0,0,0,0,0};
		gPlayerLevelInfo[id][wpn] = LEVEL_NONE;
	}
}

stock bool:isPlayerMoving(id){	
	if(!is_user_alive(id))
		return false;
		
	new Float:vVel[3];
	pev(id, pev_velocity, vVel);
	if(vector_length(vVel) > 0.001){
		return true;
	}
	return false;
}

stock defaultPlayerSettings(id){
	gPlayerSettings[id][SETTINGS_DISP_RANK] = 1;
	gPlayerSettings[id][SETTINGS_DISP_WPN_LVL] = 1;
	gPlayerSettings[id][SETTINGS_SHOW_LVL_ON_KILL] = 1;
	gPlayerSettings[id][SETTINGS_SHOW_LVL_ON_WPN_CHANGE] = 1;
	gPlayerSettings[id][SETTINGS_DISP_X] = _:-1.0;
	gPlayerSettings[id][SETTINGS_DISP_Y] = _:-1.0;
}

stock displayIfno(id, Float:holdtime){
	new rank = gPlayerRank[id];
	new xp = gPlayerXp[id][T_TOTAL];
	new msg[128];
	new rankName[62];
	getRankName(id, rank, rankName, 61);
	
	new Float:x =  gPlayerSettings[id][SETTINGS_DISP_X]; 
	new Float:y =  gPlayerSettings[id][SETTINGS_DISP_Y];
	
	if(rank < RANK_GENERAL_OF_THE_ARMY){
		new nextRank = rank++;
		new nextRankXp = RANK_REQ[nextRank];
		
		formatex(msg, charsmax(msg), "%L: %s XP: %d %L: %d", id, "YOUR_RANK", rankName, xp, id, "TO_PROMOTION", nextRankXp-xp);
	} else {
		formatex(msg, charsmax(msg), "%L: %s XP: %d", id, "YOUR_RANK", rankName, xp);
	}
	
	if(gPlayerSettings[id][SETTINGS_DISP_WPN_LVL]){
		new wpn = 0;
		if(is_user_alive(id))
			wpn = get_user_weapon(id);
			
		if(isLevelWeapon(wpn)){
			new lvl = gPlayerLevelInfo[id][wpn];
			if(lvl!=LEVEL_NONE){
				getLevelName(id, lvl, rankName, charsmax(rankName));
				format(msg, charsmax(msg), "%s^n%L: %s", msg, id, "WEAPON_LEVEL", rankName);
			}
		}
	}
	
	set_hudmessage(0, 0, 255, x, y, 0, 6.0, holdtime, 0.1, 0.2, 7);
	ShowSyncHudMsg(id, rankHud, msg);

}
